package com.boxin.ims.modules.wechat.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.boxin.framework.base.dao.DaoHelper;
import com.boxin.framework.base.dao.OpResult;
import com.boxin.ims.modules.sys.scheduler.SchedulerInfo;
import com.boxin.ims.modules.wechat.entity.WechatMember;

/**
 * @author Jakemanse
 * @date 2013-9-23
 * @function <p> 信微模块通知  SQL Map查询操作</p>
 */
@Service
public class WechatDaoHelper {
	
	@Autowired
	private DaoHelper daoHelper;
	
	/**
	 * @author Jakemanse
	 * @time 2013-9-23  上午11:36:55
	 * @function <p> 被动抽奖的人员范围 </p>
	 * @param params{day,userId}
	 * @return
	 */
	public List<Map<String,Object>> queryNewMembers(Map<String,String> params){
		
		return daoHelper.queryForList("com.boxin.ims.wechat.queryNewMembers", params);
	}
	
	
	public List<Map<String,Object>> queryQueueMembers(Map<String,String> params){
		
		return daoHelper.queryForList("com.boxin.ims.wechat.queryQueueMembers", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-7  下午11:48:32
	 * @function <p> 查询会员的商家抽奖中奖列表，其中不包括过期的  </p>
	 * @param member
	 * @return
	 */
	public List querySellerLotteryRecordByMember(Map<String,Object> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.queryLotteryRecordByMember", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-15  上午10:01:07
	 * @function <p>用户主动抽奖  </p>
	 * @param member
	 * @return
	 */
	public List queryMineLotteryRecordByMember(Map<String,Object> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.queryMineLotteryRecordByMember", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-12-28  下午2:22:20
	 * @function <p> 查询注册礼品  </p>
	 * @param params
	 * @return
	 */
	public List queryMyRegLotteryRecordByMember(Map<String,Object> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.queryMyRegLotteryRecordByMember", params);
	}
	
	
	
	
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-5  下午11:02:40
	 * @function <p> 是否已加入抽奖队列 </p>
	 * @param member
	 * @return
	 */
	public boolean isInLotteryQueue(WechatMember member){
		int row = daoHelper.queryForTotalRow("com.boxin.ims.wechat.queryInLotteryQueue", member);
		
		return (row>0);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-10  上午10:09:19
	 * @function <p>  </p>
	 * @param params 
	 *    day
	 *    month
	 *    userId
	 *    status
	 *    awardType (值：lottery,seckill,share,exchange)
	 * @return
	 */
	public List<Map<String,Object>> queryAwardStaticsByDay(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.statics.queryAwardStaticsByDay", params);
	}
	
	public List<Map<String,Object>> queryAwardStaticsByMonth(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.statics.queryAwardStaticsByMonth", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-11  下午2:20:36
	 * @function <p> 获取当前会员的优惠券个数 </p>
	 * @param params
	 * @return
	 */
	public int getMyTodayCouponCount(Map<String,String> params){
		return daoHelper.queryForTotalRow("com.boxin.ims.wechat.queryCouponByOpenId", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-14  下午4:01:33
	 * @function <p> 查询我的优惠券 </p>
	 * @param params
	 * @return
	 */
	public List<Map<String,Object>> queryCoupons(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.queryCoupons", params);
	}
	
	
	public void cleanLotteryQueue(Map<String,String> params){
		 daoHelper.delete("com.boxin.ims.wechat.cleanLotteryQueue", params);
	}
	
	
	
	public List<Map<String,Object>> queryMembers(Map<String,Object> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.statics.queryMembers", params);
	}
	
	public List<Map<String,Object>> queryLotteryData(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.statics.queryLotteryData", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-13  下午11:28:32
	 * @function <p> 核销的统计 </p>
	 * @param params
	 * @return
	 */
	public List<Map<String,Object>> queryAllStatusLotteries(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.statics.queryAllStatusLotteries", params);
	}
	
	
	public List<Map<String,Object>> queryCategoryLotteries(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.statics.queryCategoryLotteries", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-14  下午1:43:51
	 * @function <p> 查询所有核销过的奖品数量 </p>
	 * @param params
	 * @return
	 */
	public List<Map<String,Object>> queryAllUsedAwards(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.statics.queryAllUsedAwards", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-11-14  上午12:17:33
	 * @function <p> 根据核销终端统计  </p>
	 * @param params
	 * @return
	 */
	public List<Map<String,Object>> queryAllUsedAwardsByTerminal(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.statics.queryAllUsedAwardsByTerminal", params);
	}
	
	
	
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-14  下午1:43:51
	 * @function <p> 查询所有未核销过的奖品数量 </p>
	 * @param params
	 * @return
	 */
	public List<Map<String,Object>> queryAllUnusedAwards(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.statics.queryAllUnusedAwards", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-14  下午3:09:10
	 * @function <p> 查询明细 </p>
	 * @param params
	 * @return
	 */
	public List<Map<String,Object>> queryMemberAwardsDetails(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.statics.queryMemberAwardsDetails", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-16  上午9:49:24
	 * @function <p> 查询所有调度器 </p>
	 * @param params
	 * @return
	 */
	public List<Map<String,Object>> queryAllSchedulers(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.sys.scheduler.queryValidSchedulers", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-16  上午9:56:14
	 * @function <p> 查询所有秒杀  </p>
	 * @param params
	 * @return
	 */
	public List<Map<String,Object>> queryAllSeckills(Map<String,String> params){
		return daoHelper.queryForList("com.boxin.ims.wechat.queryAllSeckills", params);
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-16  上午10:01:56
	 * @function <p>  </p>
	 */
	public void updateSeckillNextStartTime(Map<String,String> params){
		daoHelper.update("com.boxin.ims.wechat.updateSeckillNextStartTime",params);
	}
	
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-16  上午11:46:15
	 * @function <p>  </p>
	 * @param params
	 * @return
	 */
	public SchedulerInfo findSchedulerInfo(Map<String,String> params){
			SchedulerInfo schedulerInfo = (SchedulerInfo)	daoHelper.queryForObject("com.boxin.ims.sys.scheduler.queryScheduler", params);
			return schedulerInfo;
	}
	
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-18  下午11:04:53
	 * @function <p> 抽奖过期作废 </p>
	 * @return
	 */
	public OpResult updateOvertimeLottery(){
		return daoHelper.update("com.boxin.ims.wechat.updateOvertimeLottery");
	}
	/**
	 * @author Jakemanse
	 * @time 2013-10-18  下午11:11:50
	 * @function <p> 优惠券过期作废 </p>
	 * @return
	 */
	public OpResult updateOvertimeCoupon(){
		return daoHelper.update("com.boxin.ims.wechat.updateOvertimeCoupon");
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-18  下午11:15:02
	 * @function <p> 转发有奖过期作废 </p>
	 * @return
	 */
	public OpResult updateOvertimeShare(){
		return daoHelper.update("com.boxin.ims.wechat.updateOvertimeShare");
	}
	
	/**
	 * @author Jakemanse
	 * @time 2013-10-18  下午11:15:16
	 * @function <p>  秒杀中奖过期作废 </p>
	 * @return
	 */
	public OpResult updateOvertimeSeckill(){
		return daoHelper.update("com.boxin.ims.wechat.updateOvertimeSeckill");
	}
	
	

	
	/**
	 * @author Jakemanse
	 * @time 2013-12-28  下午3:25:45
	 * @function <p> 获取预订的空闲时间 </p>
	 * @param params
	 * @return
	 */
	public List<Map<String,Object>>findFreeTimequantum(Map<String,String>  params){
		return daoHelper.queryForList("com.boxin.ims.wechat.book.findFreeTimequantum", params);
	}
	
	
	
	/**
	 * @author Jakemanse
	 * @time 2013-12-30  上午12:07:07
	 * @function <p> 查询预订 </p>
	 * @param params
	 * @return
	 */
	public List<Map<String,Object>>findBookOrderRecord(Map<String,String>  params){
		return daoHelper.queryForList("com.boxin.ims.wechat.book.findBookOrderRecord", params);
	}
	
	
	public int updateBookOrderRecord(Map<String,String> params){
		OpResult result = 	daoHelper.update("com.boxin.ims.wechat.book.updateBookOrderRecord", params);
		return 0;
		
	}
	

}
